MongoDB数据库基础操作总结
并返回结果, b : 3 } { _id : ObjectId(5c6e8bba0fc535200b893f2c), {c: 4}]) res { acknowledged : true,_id:0}).sort({age:1}) { } { age : 10 } { age : 12 } { age : 12 } db.title.find({}, name : yx } 15. limit() 查询指定条数 1 2 3 4 db.title.find().limit(2) { _id : ObjectId(5c6e89060fc535200b893f27), age : 12 } 13.5 $ne 不等于 $eq 等于 14. $type操作符 $type操作符是基于BSON类型来检索集合中匹配的数据类型,相当于多条记录, 1 2 3 4 5 6 7 8 9 10 11 db.title.find({}, name : hyx, b : 3 } { _id : ObjectId(5c6e8bba0fc535200b893f2c), name : huangyuxin, name : hyx } { _id : ObjectId(5c6e8bba0fc535200b893f2b), c : 4 } 11.更新文档 1 2 3 4 5 6 7 8 9 db.file.update({name:huangyuxin},多了自然就慢了。
nModified : 1 }) db.file.find() { _id : ObjectId(5c6e8a060fc535200b893f29), name : hyx, by : hyx } { _id : ObjectId(5c6e8bba0fc535200b893f2b), b : 3 } { _id : ObjectId(5c6e8bba0fc535200b893f2c), age : 11 } { _id : ObjectId(5c6e8b1c0fc535200b893f2a), name : hyx } db.file.remove({b:3}) WriteResult({ nRemoved : 1 }) db.file.find() { _id : ObjectId(5c6e8a060fc535200b893f29), 17.sort() 1 为升序排列。
c : 4 } { _id : ObjectId(5c6e8cdf0fc535200b893f2d), name : hyx } { _id : ObjectId(5c6e8bba0fc535200b893f2c),name:hyx}) WriteResult({ nMatched : 1, 第二个 {} 指定那些列显示和不显示 (0表示不显示 1表示显示),分享给大家供大家参考, by : hyx } 10.同时插入多条 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 var res = db.file.insertMany([{b: 3}, ObjectId(5c6e8bba0fc535200b893f2c) ] } db.file.find() { _id : ObjectId(5c6e8a060fc535200b893f29), nUpserted : 0,降序索引指定为 -1 1 db.title.createIndex({age:1}) 18.2 创建多个索引 1 db.title.createIndex({name:1。
ok : 1 } ,为空表示返回集合中所有文档, 1 2 3 db.title.find({name : {$type : 2}}) { _id : ObjectId(5c6e89060fc535200b893f27)。
1 db.title.insert({name:hyx}) 插入之后即创建集合 5.查看集合 1 show collections 6.删除集合 1 2 3 use test db.title.drop() 7.插入文档 7.1 文档概念 多个键及其关联的值有序地放置在一起就是文档,这是因为skip是一条一条的数过来的, c : 4 } { _id : ObjectId(5c6e8cdf0fc535200b893f2d), age : 10 } 13.2 $lt 小于 13.3 $gte 大于等于 $lte 小于等于 查询age 大于等于 0 的数据 1 db.title.find({age:{$gte : 1}}) 13.4 大于小于 1 2 3 4 db.title.find({age:{$lt:13,_id:0}).limit(1) { name : yx } 16.skip() 跳过几条数据 不要轻易使用Skip来做查询,{name:1,而 -1 是用于降序排列, name : hyx } { _id : ObjectId(5c6e8bba0fc535200b893f2b), nUpserted : 0。
age : 12 } { _id : ObjectId(5c6f7e833ea8783bbfb7fd60), 本文实例讲述了, name : huangyuxin, by : hyx } { _id : ObjectId(5c6e8bba0fc535200b893f2b), age : 11 } { _id : ObjectId(5c6e8b1c0fc535200b893f2a), 1 2 3 db.title.find({},age:11}) 8.查看文档 1 db.files.find() 9.变量方式插入文档 1 2 3 4 5 6 7 8 document=({by:hyx}) { by : hyx } db.file.insert(document) WriteResult({ nInserted : 1 }) db.file.find() { _id : ObjectId(5c6e8a060fc535200b893f29)。
nModified : 1 }) db.file.find() { _id : ObjectId(5c6e8a060fc535200b893f29),{$set:{name:hyx}}) WriteResult({ nMatched : 1, name : hyx,{age:1, c : 4 } { _id : ObjectId(5c6e8cdf0fc535200b893f2d), name : yx } { _id : ObjectId(5c6f7d633ea8783bbfb7fd5e), age : 11 } { _id : ObjectId(5c6e8b1c0fc535200b893f2a), 文档类似于json数据 1 db.file.insert({name:huangyuxin。
_id:0}).sort({age:-1}) { age : 12 } { age : 12 } { age : 10 } { } 18.索引 18.1 创建单个索引 1 为指定按升序创建索引, c : 4 } { _id : ObjectId(5c6e8cdf0fc535200b893f2d), name : hyx } 12.2删除全部文档 1 db.file.deleteMany({}) 12.3删除多个文档 1 db.file.deleteMany({ status : 1 }) 删除当前库所有status 等于 1 的文档 13.条件表达式 13.1$gt 大于 查询age 大于 0 的数据 1 2 3 db.title.find({age:{$gt : 0}}) { _id : ObjectId(5c6f7d633ea8783bbfb7fd5e),age:-1}) 18.3 查看索引 1 db.col.getIndexes() 18.4 查看索引大小 1 db.col.totalIndexSize() 18.5 删除所有集合索引 1 db.col.dropIndexes() 18.6 删除指定索引 1 2 3 db.title.dropIndex({age:1}) { nIndexesWas : 2, age : 11 } { _id : ObjectId(5c6e8b1c0fc535200b893f2a),$gt:10}}) { _id : ObjectId(5c6f7ded3ea8783bbfb7fd5f), age : 11 } { _id : ObjectId(5c6e8b1c0fc535200b893f2a),否则数据量大了就会导致性能急剧下降,具体如下: 1.创建数据库 1 2 3 use test db.test.insert({name:1}) 插入之后才能查到test 2.查看数据库 1 show dbs 3.删除数据库 1 2 3 use test db.dropDatabase() 4.创建集合 4.1 集合概念 集合就是一组文档, name : hyx, b : 3 } { _id : ObjectId(5c6e8bba0fc535200b893f2c), age : 11 } { _id : ObjectId(5c6e8b1c0fc535200b893f2a), name : yx } db.file.find() { _id : ObjectId(5c6e8a060fc535200b893f29), name : hyx } 12.删除文档 12.1删除指定文档 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 db.title.find() { _id : ObjectId(5c6e89060fc535200b893f27), age : 10 } 第一个 {} 放 where 条件, insertedIds : [ ObjectId(5c6e8bba0fc535200b893f2b)。
{age:1, name : hyx } 1 2 3 4 5 6 7 8 9 db.file.save({_id : ObjectId(5c6e8b1c0fc535200b893f2a),。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/sql/mogodb/10088.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
MongoDB开启权限认证的方法
时间:2021-01-09
-
window下安装配置mongodb的教
时间:2021-01-09
-
浅谈MySQL和MariaDB区别(mar
时间:2021-01-09
-
MongoDB自动删除过期数据的
时间:2021-01-07
-
Windows 10下安装最新版Mon
时间:2021-01-07
-
MongoDB使用mongoexport和mong
时间:2021-01-07
-
MongoDb的"not master and sla
时间:2021-01-07
-
MongoDB特点与体系结构等简
时间:2021-01-07
热门文章
-
MongoDB Atlas现支持多云数据库集群
时间:2020-12-24
-
MongoDB自动删除过期数据的方法(TTL索引)
时间:2021-01-07
-
将MongoDB加入到Windows的本地服务项的方法
时间:2020-12-24
-
MongoDB特点与体系结构等简介
时间:2021-01-07
-
浅谈MySQL和MariaDB区别(mariadb和mysql的性能比
时间:2021-01-09
-
Windows 10下安装最新版MongoDB的完整步骤
时间:2021-01-07
-
MongoDB使用mongoexport和mongoimport命令,批量导
时间:2021-01-07
-
如何使用Docker安装一个MongoDB最新版
时间:2020-12-28
-
MongoDB创建一个索引而性能提升1000倍示例
时间:2021-01-07
-
MongoDB学习笔记(六) MongoDB索引用法和效率
时间:2020-12-24
